<?php
namespace Home\Controller;
import('Util.Page');
/**
 * 个人中心添加域名注册商
 * @author Administrator
 *
 */
class RegbusinessController extends HomeBaseController
{
    public function index(){
        $arry=array('uid' => session('uid'));
        $count = D('UserRegbusiness')->getCount($arry);
        $list = D('UserRegbusiness')->getList($arry);
        $this->assign('list', $list);
        $this->assign('count', $count);
        $this->display('regbusiness/index');
    }
    
    
    public function getCount(){
        $resp['count']=0;
        $arry=array('uid' => session('uid'));
        $count = D('UserPacket')->count_userPackets($arry);
        $resp['count']=$count;
        $this->ajaxReturn($resp,'JSON');
    }
    
    /**
     * 查询平台注册商
     */
    public function gePlatRegbusiness(){
        $list = M('register_business')->select();
        $this->ajaxReturn($list,'JSON');
    }
    
    
    /**
     * 短信验证码发送
     */
    public function sendMobileMes(){
        /**
         * 校验图片验证码
         * */
         $regverify=I('imgcode',1);
         $imgCodeId=I('imgCodeId',1);
         $verify = new \Think\Verify();
         if(!$verify->check($regverify, $imgCodeId)) {
             $this->ajaxReturn(array('code'=>'error','info' => '验证码错误或已过期！'));//0错误，1成功
             exit;
         };
        $MessEvent=D('Mess','Event');
        $resp = $MessEvent->sendMobileMes(I('mobile',''));
        $this->ajaxReturn($resp,'JSON');
    
    }
    
    /**
     * 邮箱验证码发送
     */
    public function sendEmailMes(){
        /**
         * 校验图片验证码
         * */
        $regverify=I('imgcode',1);
         $imgCodeId=I('imgCodeId',1);
         $verify = new \Think\Verify();
         if(!$verify->check($regverify, $imgCodeId)) {
             $this->ajaxReturn(array('code'=>'error','info' => '验证码错误或已过期！'));//0错误，1成功
             exit;
         };
        $MessEvent=D('Mess','Event');
        $resp = $MessEvent->sendEmailMes(I('email',''));
        $this->ajaxReturn($resp,'JSON');
    }
    
    
    /**
     * 插入平台注册商
     */
    public function save(){
        $resp['status']=0;
        if(I('post.mobile','') != ''){
            $result = D('Mess','Event')->checkCode(I('post.codeMobile',''));
            if($result["status"] == 0){
                $this->ajaxReturn($result,'JSON');
                exit();
            }else{
                session('registerCode',null);
            };
        };
        if(I('post.email','') != ''){
            $result = D('Mess','Event')->checkCode(I('post.codeEmail',''));
            if($result["status"] == 0){
                $this->ajaxReturn($resp,'JSON');
                exit();
            }else{
                session('registerCode',null);
            }
        };
        $arry=array(
            'uid' =>session('uid'),
            'businesid' => I('post.businesid',null),
            'busicode' => I('post.busicode',null),
            'email' => I('post.email',null),
            'mobile' => I('post.mobile',null)
        );
        $result = D('UserRegbusiness')->inst($arry);
        if($result["status"] == 0){
            $resp['msg']=$result["mess"];
        }else{
            $resp['status']=1;
            $resp['msg']="添加成功！";
        }
        $this->ajaxReturn($resp,'JSON');
    }
    
    
}